import html from './share.html'
import './share.css'

export default {
  clickLi: function (target) {
    while (!target.dataset.tag && target !== document.body) {
      target = target.parentNode
    }
    if (target.dataset.tag) {
      window.alert(target.dataset.tag)
    }
  },
  init: function () {
    var div = document.createElement('div')
    var me = this
    this.div = div
    div.id = '__plugins_share__'
    div.innerHTML = html
    document.body.appendChild(div)

    div.addEventListener('click', function (e) {
      var target = e.target
      if (target.id === '__plugins_share__' || target.id === '__plugins_share_cancel__') {
        me.hide()
      } else {
        me.clickLi(target)
      }
    })
  },
  show: function () {
    var div = document.getElementById('__plugins_share__')
    if (div) {
      div.style.display = 'block'
    } else {
      this.init()
    }
  },
  hide: function () {
    this.div.style.display = 'none'
  }
}
